Survo C codes for MAT #QFIND, MAT #QRFIND, and CTEST: /* #qfind.c 3.5.2017/SM (17.5.2017) */ #include #include #include #include #include #include #include #include "ext_mat.h" extern char *argv1; static int i,n,h,j,jj; static int n21,i0; static int row,col; static int *Q,*perm; static int *P,*P2; extern char **spb; int np; static char name[64]; // MAT #QFIND(n) or MAT #QFIND(n,TEST) FILE *tmp; op__qfind() { i=external_mat_init(1); if (i<0) return(1); if (g<3) { init_remarks(); rem_pr("MAT #QFIND(n,TEST) "); rem_pr("http://www.survo.fi/papers/Roots2013.pdf "); rem_pr("creates nxn Qn table (2017) "); rem_pr("Optional TEST checks the properties of Qn"); wait_remarks(2); return(1); } n=1+atoi(word[2]); np=0; if (g>3) np=n; if (i>0) { P=malloc(np*sizeof(int)); P2=malloc(np*sizeof(int)); } sprintf(sbuf,"Q%d.TXT",n-1); tmp=fopen(sbuf,"wt"); n21=2*n+1; Q=malloc(2*n21*(n+1)*sizeof(int)); perm=malloc(2*(n+1)*sizeof(int)); for (i=0; i2) { Q[j++]=-Q[jj--]; } j=h+1; while (j<(col+1)*n21) { Q[j]=2*Q[j-col]-Q[j-2*col]; ++j; } ++col; } fclose(tmp); external_mat_end(argv1); return(1); } set_row(k) int k; { int j,h,i; j=1; h=n21+n+k; while (j<=n) { for (i=0; in) break; h+=n21; } if (j>n) break; for (i=0; in) break; h+=n21; } Q[h]=0; j++; h+=n21; if (j>n) break; } return(1); } // None of error messages in this function should appear! int test(n) int n; { int i,j; if (P[0]!=n) { printf("\nQFIND: The first element is not the greatest one %d !", n); getch(); exit(0); } for (i=0; i #include #include #include #include #include #include #include "ext_mat.h" extern char *argv1; static int i,n,m,k,j,q,i1; static double *D,*H; static double *X; static double *C; static int *Q; static int am; static FILE *tmp; static char name[64]; static char *lab; // MAT #QRFIND(n,Q,matrix) extern double pi; extern double sgn(); extern double cot(); op__qrfind() { char expr1[2*LLENGTH]; double a,b,gg,gap; int odd=0; int c_q,c_factor,c_index,c_amod; int f; i=external_mat_init(1); if (i<0) return(1); if (g<4) { init_remarks(); rem_pr("MAT #QRFIND(n,Q,A) "); rem_pr("http://www.survo.fi/papers/Roots2013.pdf "); rem_pr("Numerical roots directly as cot expressions! (2017) "); rem_pr(" "); rem_pr("sign, q, factor, index, amod values saved as A.MAT "); rem_pr("q values obtained from Q file generated by "); rem_pr("MAT #QFIND. "); rem_pr("Matrix of coefficients saved as Cn.MAT "); wait_remarks(2); return(1); } n=atoi(word[2]); odd=1; if (n%2==0) odd=0; m=n/2; i=spec_init(r1+r-1); if (i<0) return(-1); Q=(int *)calloc(m*m,sizeof(int)); tmp=fopen(word[3],"rt"); for (i=0; i0) { ++i; q=1; continue; } am=amod(n,2*i-1); if (am==0) q=0; else q=Q[(i-2)*m+am-1]; if (q>0) { if (n%2==0) { if (i%2==0) T[i-1]=-1; else T[i-1]=1; } else { if (q%2==i%2) T[i-1]=-1; else T[i-1]=1; } T[c_q+i-1]=q; ++i; continue; } else { // If no valid q is found, Q // X[i-1] must be a 'factor' root. a=X[i-1]; f=(int)(pi/(2*atan(1.0/a))+0.5); if (n%f!=0) { // This error message should never appear! sprintf(sbuf,"\n%d is not a factor of %d!", f,n); sur_print(sbuf); getch(); return(1); } gap=n/f; // Recording other roots related to f i1=i; q=1; while (i1<=m) { T[c_factor+i1-1]=f; T[c_index+i1-1]=q; i1+=(int)gap; ++q; } ++i; iprint(i); q=1; continue; } } // i mT=m; nT=5; strcpy(exprT,"Exact_roots"); i=save_T(word[4]); // 3.4.2017 Coefficient matrix -> Cn.MAT C=malloc(m*m*sizeof(double)); for (i=0; i(int)(i/2)) mod=i-mod; return(mod); } double sgn(x) double x; { if (x>0.0) return(1.0); if (x<0.0) return(-1.0); return (0.0); } double cot(double x) { return (1/tan(x)); } /* _ctest.c 19.5.2017/SM (19.5.2017) */ #include #include #include #include #include #include #define MMAX 1001 #define PI 3.141592653589793 unsigned int n,m; char bin[MMAX]; double ee[MMAX],rr[MMAX]; int ns[MMAX]; __int64 fs[MMAX]; FILE *temp; void main(argc,argv) int argc; char *argv[]; { int i; __int64 j; double a,accuracy; int k,nn; if (argc==1) return; s_init(argv[1]); if (g<2) { sur_print("\nCTEST n,accuracy "); sur_print("\nscans all 2^[(n-1)/2-1] positive linear combinations "); sur_print("\nof edge and chord engths of a n-sided regular polygon "); sur_print("\nwith coefficients +1 or -1 "); sur_print("\nand checks that only one of them is equal to "); sur_print("\ncot((2*i+1)*pi/(2*n)), i=1,2,...,(n-1)/2. "); sur_print("\nfor a prime number n. "); sur_print("\nExample: CTEST 79,0.0000000000001 "); WAIT; return; } n=atoi(word[1]); m=(n-1)/2; accuracy=atof(word[2]); for (i=0; i9999999) { printf("M"); k=0; } if (a>0.0) // check positive combinations for (i=0; i=0) --i; if (i<0) break; bin[i]='1'; ++i; for (; i